package net.sos.playground;

public class EnumTest {
   
   public static void main(final String[] args) {
      String en = "enr";
      System.out.println(Lang.fromString(en));
   }
   
}

enum Lang {
   
   ENGLISH("en"),
   FRENCH("fr");
   
   private String language;
   
   Lang(final String language) {
      this.language = language;
   }

   public static Lang fromString(String value) {
      for(Lang lang : Lang.values()) {
         if(lang.language.equals(value)) {
            return lang;
         }
      }
      throw new IllegalArgumentException("Invalid language: " + value);
   }
   
   @Override
   public String toString() {
      return this.language;
   }
   
}